/*
 ============================================================================
 Name        : ISBN_10.c
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

char prufziffberechn_10(int isbn_num_10) {
	int summe = 0, pz1 = 0;
	//int pz = 0;
	char pz;
	int i, ziff = 0;
	int pot = 1;

	for (i = 2; i <= 10; i++) {

		ziff = (isbn_num_10 / pot) % 10;
		pot = pot * 10;
		printf("%d x %d \n", ziff, i);
		summe = summe + (ziff * i);

		pz1 = summe % 11;

		pz = 11 - pz1;

		if (pz == 10)
			pz = 88;
		else if (pz == 11)
			pz = 48;

		else
			pz = 48 + pz;

	}

	printf("\n%d mod 11 = %d \n", summe, pz1);
	printf("11-%d=", pz1);
	return pz;
}

int prufziffberechn_13(long long isbn_num13) {
	int summe = 0, gewicht = 0, grad_oder_nicht = 0;
	int i;
	long long ziff = 0;
	long long pot = 1;

	for (i = 2; i <= 13; i++) {

		ziff = (isbn_num13 / pot) % 10;
		pot = pot * 10;

		grad_oder_nicht = i % 2;
		if (grad_oder_nicht == 0)
			gewicht = 3;
		else
			gewicht = 1;
		summe = summe + (ziff * gewicht);
		printf("%d) %d x %d \n", i - 1, (int) ziff, gewicht);

	}
	printf("\n%d mod 10 = %d \n", summe, summe % 10);

	summe = summe % 10;
	printf("10-%d =", summe);
	return 10 - summe;
}

int pruf_mit_bindestrich(char* isbn) {
	int ergebnis;

	while (strcmp(isbn, "\0") != 0) {

		if (*isbn != 45) {
			ergebnis = *isbn - 48;
			printf("\n%d", ergebnis);
			isbn++;

		} else {
			isbn++;
		}
	}

//ergebnis = *isbn - 48;

//printf("\n%s", isbn);

	return ergebnis;
}

void test_array(char test[]){
	int i=0, lenge;
	lenge = strlen(test);
	while (i <= lenge)
	{
		if (test[i]== '-')
			printf ("\nich habe bindestrich gefunden");
		else printf ("\narray_test %c", test[i]);
			i =i+1;
	}

	printf("\n laenge von array = %d", lenge);
}


int main(void) {
	char* isbn = "123-5678";

	char test[] = "test-12345";
	printf("%c <-- Prufsumme  \n\n\n\n", prufziffberechn_10(344619313)); // 3-88229-192-3   also 3    * 3-499-13599-x
	printf("%d <-- Prufsumme \n", prufziffberechn_13(978388229192)); // 978-3-88229-192-6  also 6
	//printf("%d <-- Prufsumme_Char \n", pruf_mit_bindestrich(isbn)); // 978-3-88229-192-6  also 6
	pruf_mit_bindestrich(isbn);

	test_array(test);
//	printf("\ntest array = %c", test[4]);

	return 0;
}
